
#!/bin/bash

echo "创建完整的项目结构..."

# 创建目录结构
mkdir -p MultiThreadTimeoutManager/{include,src,tests,build,examples}
mkdir -p MultiThreadTimeoutManager/include/{core,common,utils}
mkdir -p MultiThreadTimeoutManager/src/{core,common,utils}

# 移动头文件到include目录
echo "组织头文件..."
mv Types.h MultiThreadTimeoutManager/include/common/
mv ThreadSafe.h MultiThreadTimeoutManager/include/common/
mv TaskWrapper.h MultiThreadTimeoutManager/include/core/
mv TimeWheel.h MultiThreadTimeoutManager/include/core/

# 移动源文件到src目录
echo "组织源文件..."
mv TimeWheel.cpp MultiThreadTimeoutManager/src/core/

# 移动测试文件到tests目录
echo "组织测试文件..."
mv test_basic.cpp MultiThreadTimeoutManager/tests/
mv test_task_wrapper.cpp MultiThreadTimeoutManager/tests/
mv test_time_wheel.cpp MultiThreadTimeoutManager/tests/

# 创建新的编译脚本，适应新的目录结构
cat > MultiThreadTimeoutManager/compile_all.sh << 'EOF'
#!/bin/bash

echo "编译完整项目..."

# 设置包含路径
INCLUDE_PATH="-Iinclude/common -Iinclude/core -Iinclude/utils"
CXX_FLAGS="-std=c++11 -pthread -O2"

# 创建构建目录
mkdir -p build

echo "编译基础组件测试..."
g++ $CXX_FLAGS $INCLUDE_PATH -o build/test_basic tests/test_basic.cpp

echo "编译TaskWrapper测试..."
g++ $CXX_FLAGS $INCLUDE_PATH -o build/test_task_wrapper tests/test_task_wrapper.cpp

echo "编译TimeWheel测试..."
g++ $CXX_FLAGS $INCLUDE_PATH -o build/test_time_wheel src/core/TimeWheel.cpp tests/test_time_wheel.cpp

if [ $? -eq 0 ]; then
    echo "所有组件编译成功！"
    echo ""
    echo "运行测试:"
    echo "1. 基础组件: ./build/test_basic"
    echo "2. TaskWrapper: ./build/test_task_wrapper"
    echo "3. TimeWheel: ./build/test_time_wheel"
    echo ""
    
    echo "运行所有测试..."
    echo "==================="
    echo "测试基础组件:"
    ./build/test_basic
    echo ""
    echo "测试TaskWrapper:"
    ./build/test_task_wrapper
    echo ""
    echo "测试TimeWheel:"
    ./build/test_time_wheel
else
    echo "编译失败！"
    exit 1
fi
EOF

chmod +x MultiThreadTimeoutManager/compile_all.sh

echo "项目结构创建完成！"
echo "进入项目目录: cd MultiThreadTimeoutManager"
echo "运行所有测试: ./compile_all.sh"
